package model

import "github.com/gin-gonic/gin"

type FirstGrade struct {
	ENo                string `gorm:"column:e_no"`
	PoliticeGrade      string `gorm:"column:politics_grade"`
	FlanguageGrade     string `gorm:"column:flanguage_grade"`
	BProfessionalGrade string `gorm:"column:b_professional_grade"`
}

func InsertFirstGrade(c *gin.Context) (error, FirstGrade) {
	var firstgrade FirstGrade
	c.BindJSON(&firstgrade)
	err := DB.Table("firstgrades").Create(&firstgrade).Error
	return err, firstgrade
}

func GetFirstGrade(firstgradeparam map[string]interface{}) (error, []FirstGrade, int64) {
	var firstgradedata []FirstGrade
	page := firstgradeparam["page"].(int)
	pageSize := firstgradeparam["limit"].(int)
	searchText := firstgradeparam["searchText"].(string)
	var total int64
	err := DB.Table("firstgrades").Where("e_no like ? ", "%"+searchText+"%").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&firstgradedata).Error
	return err, firstgradedata, total
}
